package bean;

/**
 * @author: android 超级兵
 * @create: 2022-01-18 16:04
 * TODO
 **/
public class WaitAndNotifyBean {

    private String name = "张三";

    // 等待
    public synchronized void waitName(String threadName) {
        try {
            // name != 李四 就等待
            while (!this.name.equals("李四")) {
                System.out.println("name:" + threadName + "等待开始啦.. ");
                wait();
                System.out.println("等待结束啦.. name:" + threadName);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    // 改变
    public synchronized void changeName() {
        this.name = "李四";
        notifyAll();
    }
}
